package com.cc.config;

import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.apache.ibatis.session.Configuration;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * @author 33314
 * @version 1.0
 * @description: TODO
 * @date 2025/6/24 14:49
 */
public class MybatisConfig {
    @Bean
    public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) {
        SqlSessionFactoryBean ssfb = new SqlSessionFactoryBean();
        ssfb.setDataSource(dataSource);
        Configuration cfg = new Configuration();
//        是否开启缓存
        cfg.setCacheEnabled(true);
//        日志
        cfg.setLogImpl(StdOutImpl.class);
        ssfb.setConfiguration(cfg);
        return ssfb;
    }

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setBasePackage("com.cc.mapper");
        return mapperScannerConfigurer;
    }
}
